package com.tuozixuan.graphql.company.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.tuozixuan.graphql.company.model.Company;
import com.tuozixuan.graphql.company.service.CompanyService;

@Service
public class CompanyServiceImpl implements CompanyService {

    @Override
    public List<Company> getCompanyList() {
        
        List<Company> companyList = new ArrayList<>();
        Company company = new Company();
        company.setId(Long.valueOf(1));
        company.setName("one");
        company.setAge(Integer.valueOf("10"));
        company.setAddress("aaaaaaaaaaaaaa");
        company.setSalary(Double.valueOf("10000"));
        companyList.add(company);
        
        company = new Company();
        company.setId(Long.valueOf(2));
        company.setName("Two");
        company.setAge(Integer.valueOf("20"));
        company.setAddress("bbbbbbbbbbbbbb");
        company.setSalary(Double.valueOf("20000"));
        companyList.add(company);
        
        return companyList;
    }

    @Override
    public Company getCompanyById(Long id) {
        return this.getCompanyList()
                .stream()
                .filter(company -> company.getId().equals(id))
                .findFirst()
                .orElse(null);
    }

    @Override
    public Company createCompany(Company company) {
        System.out.println("save company....");
        return company;
    }

    @Override
    public Company updateCompany(Company company) {
        System.out.println("update company....");
        return company;
    }

    @Override
    public boolean deleteCompany(Long id) {
        System.out.println("delete company...." + id);
        return true;
    }
    
}
